package com.example.demo.admin.gecco;/**
 * Created by kete on 2017-11-07.
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.io.Files;
import com.google.common.io.Resources;

import java.io.File;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Set;

/**
 * 作者：kete
 * 创建时间：2017-11-07 15:20
 * 功能描述：
 * 版本：
 */
public class Test {

    public static String codeAdd(String code,Integer zz){
        Integer intCode = Integer.parseInt(code);

        Integer newCode = intCode+zz;

        return newCode.toString();
    }

    public static void main(String[] args) {

        String json = null;
        try {
            URL url = Resources.getResource("city.json");
            File file = new File(url.getPath());
            if(file.exists()) {
                json = Files.toString(file, Charset.forName("UTF-8"));

            }
        } catch(IllegalArgumentException ex) {

        } catch(Exception ioex) {
            ioex.printStackTrace();
        }

        JSONObject jsonObject = JSON.parseObject(json);

        String iniCode = "110000";

        JSONObject bj = jsonObject.getJSONObject(iniCode);

        String childCode = Test.codeAdd(iniCode,100);

        JSONObject array = bj.getJSONObject("child").getJSONObject(childCode).getJSONObject("child");

        System.out.printf("order :"+Integer.parseInt("09")+"\n");

        System.out.printf("name:"+array.toString()+"\n");

        Set<String> keys = array.keySet();

        keys.stream().forEach(key->{
            String zzObj = array.getString(key);


            System.out.printf("code:"+key+"\n");
            System.out.printf("name:"+zzObj.toString()+"\n");

        });

    }
}
